import React from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from "mobx"
import { WeaLocaleProvider, WeaNewScroll } from 'ecCom';
import {WeaForm} from 'comsMobx';
import { Condition, ConditionNum } from '../list/listCondition';
const getLabel = WeaLocaleProvider.getLabel;
import '../../../style/myComment/myComment.less'

import "./wea-modal.less"
import "./wea-table.less"
import "./wea-input.less"
import "./wea-select-option.less"
import "./wea-checkbox.less"
import "./wea-tabs.less"
import "./g-ckeditor-content.less"
import "../../../style/myComment/icon.css"


@inject("checkMatterStore", "proinfoStore", "topStore")
@observer
export default class Comment extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            height: 0,
            tab: [getLabel('18329', '领导批示')],
            comment: [getLabel('675', '评论')],
        }
    }

    componentDidMount() {
        const { checkMatterStore, id, type, firstComing, taskAccount } = this.props;
        let params = { "id": id, "type": type };
       
        if (taskAccount) {
            params.taskAccount = taskAccount;
        }
        if (firstComing == 1) {//第一次进来时需记录日志
            params.selectTabKey = '';
            checkMatterStore.getCheckCondition(params);
        } else {
            checkMatterStore.getCheckCondition(params);
        }
        this.setState({ height: document.body.clientHeight - 71 - 24 - 39 })
        //checkMatterStore.getTaskId(id);
        //checkMatterStore.init({"taskId":id,"pageindex":pageindex,"pagesize":pagesize});
    }

    render() {
        const { checkMatterStore, topStore,taskAccount } = this.props;
        let { pageindex, pagesize } = checkMatterStore;
        const { tasklabels, loading, form, formB, hasChild } = checkMatterStore;
        const { topIcon = "icon-coms-government", iconBgcolor = "#f14a2d" } = tasklabels;
        const { title, userInfo, weiboCKEditorConfig, basicInfo, systemWorkLog, weiboGroup, fanList, attentionList, defaultTemplate, keyWords } = toJS(this.props.checkMatterStore.status),
            { height, attentionCheck, currentGroup, isReset, tab, comment } = this.state;
        //获取评论与汇报列表数据
        const getWeiboList = () => {
            let weiboList = {};
            let dialogWeiboList = toJS(this.props.checkMatterStore.status.weiboList);
            let modelWeiboList = toJS(this.props.proinfoStore.modelStore.status.weiboList);
            if (modelWeiboList) {
                if (modelWeiboList.total > dialogWeiboList.total) {
                    weiboList = _.cloneDeep(modelWeiboList);
                } else {
                    weiboList = _.cloneDeep(dialogWeiboList);
                }
            } else {
                weiboList = _.cloneDeep(dialogWeiboList);
            }
            return weiboList;
        }
        let weiboList = getWeiboList();
        let groups = weiboGroup.groupList || [];
        let groupList = [];
        let clientWidth = parseInt(0.5 * document.documentElement.clientWidth);
        groups.forEach(
            item => {
                if (item.groupId != "all" && item.groupId != "nogroup") {
                    groupList.push(item)
                }
            }
        );
        let contentHeight = hasChild ? height * 0.50 : height;
        if(taskAccount) {contentHeight = contentHeight - 70;}
        let levelHeight = height - contentHeight - 2;
        return (
            <div className="g-detail">
                <div className="g-detail-main" >
                    {/* 任务内容 */}
                    <div style={{ marginBottom: '2px', height: `${contentHeight}px` }}>
                        <div className="g-detail-main-title">{getLabel(389235, "任务内容")}</div>
                        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@gmjm40`} height={taskAccount?contentHeight -97:(hasChild ? contentHeight - 47 : height - 45)}>
                            <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@jfdy3h`} listStore={checkMatterStore} form={form} listStore2={topStore}></Condition>
                        </WeaNewScroll>
                    </div>
                    {/* 任务阶段 */}
                    {hasChild && <div style={{ height: `${levelHeight}px` }}>
                        <div className="g-detail-main-title">{getLabel('383349,24902', '任务阶段')}</div>
                        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@kdkktm`} height={levelHeight - 45 - 21}>
                            <ConditionNum ecId={`${this && this.props && this.props.ecId || ''}_ConditionNum@dukkpg`} listStore={checkMatterStore} formB={formB} listStore2={topStore}></ConditionNum>
                        </WeaNewScroll>
                    </div>}
                </div>
            </div>
        )
    }
    changeReset = (value) => {
        this.setState({ isReset: value })
    }

    checkAttention = (value) => {
        this.setState({ attentionCheck: value })
    }

    changeGroup = (value) => {
        this.setState({ currentGroup: value.groupId })
    }
    submite() {
        const { checkMatterStore } = this.props;
        checkMatterStore.submite();

    }
}
